package zb.WX.service.msg;

import zb.WX.bean.message.Item;
import zb.WX.bean.message.PicText;
import zb.WX.util.GlobalVar;
import zb.WX.util.ObjToXmlUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 图文消息的回复
 *
 * @author Administrator
 */
public class PicTextMsg {
    private String className = this.getClass().getCanonicalName();

    //单图文消息回复
    public String singlePicText(Map<String, String> map) {
        String methodName = new Exception().getStackTrace()[0].getMethodName();
        String thisName = className + "." + methodName;

        Item item1 = new Item();
        item1.setTitle("2017版《射雕英雄传》");
        item1.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item1.setPicUrl("http://d.hiphotos.baidu.com/baike/w%3D268%3Bg%3D0/sign=ff465d583afa828bd1239ae5c5242609/54fbb2fb43166d220c32ccc94f2309f79052d222.jpg");
        item1.setUrl("http://baike.baidu.com/link?url=lzBCe5-gE2gaH686FExQCH6STqf7wmZ9kdoMoD4-Dlr2xDTXBcTYP3YWggyelVflK64PWi1QvKfoPMLkW2rr1tALg9tJc5EmbDaI1HUUuIWLbjq9rJTwWm4FmY_dPCIcJY0LuwiGjC9LfEuecSxt0a");

        List<Item> articles = new ArrayList<Item>();
        articles.add(item1);//将item1加入到articles中（只加一条item是单图文）


        PicText picText = new PicText();
        picText.setFromUserName(map.get("ToUserName"));
        picText.setToUserName(map.get("FromUserName"));
        picText.setMsgType(GlobalVar.NEWS);
        picText.setCreateTime(new Date().getTime());
        picText.setArticleCount(1);
        picText.setArticles(articles);//将article加入到picText中（只能存在一条article）

        String picTextXmlString = ObjToXmlUtil.objToXml(picText, "xml");
        System.out.println(thisName + "——单图文消息回复：" + picTextXmlString);
        return picTextXmlString;
    }

    //多图文消息回复
    public String PropertyPicText(Map<String, String> map) {
        String methodName = new Exception().getStackTrace()[0].getMethodName();
        String thisName = className + "." + methodName;

        Item item1 = new Item();
        item1.setTitle("2017版《射雕英雄传》");
        item1.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item1.setPicUrl("http://d.hiphotos.baidu.com/baike/w%3D268%3Bg%3D0/sign=ff465d583afa828bd1239ae5c5242609/54fbb2fb43166d220c32ccc94f2309f79052d222.jpg");
        item1.setUrl("http://baike.baidu.com/link?url=lzBCe5-gE2gaH686FExQCH6STqf7wmZ9kdoMoD4-Dlr2xDTXBcTYP3YWggyelVflK64PWi1QvKfoPMLkW2rr1tALg9tJc5EmbDaI1HUUuIWLbjq9rJTwWm4FmY_dPCIcJY0LuwiGjC9LfEuecSxt0a");

        Item item2 = new Item();
        item2.setTitle("《射雕英雄传》黄蓉与郭靖");
        item2.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item2.setPicUrl("http://b.hiphotos.baidu.com/baike/whfpf%3D180%2C140%2C50/sign=721cd2f1464a20a4314b6f87f66fa91a/79f0f736afc379313b5f0ccae2c4b74543a91119.jpg");
        item2.setUrl("http://www.baidu.com");

        Item item3 = new Item();
        item3.setTitle("《射雕英雄传》郭靖与他母亲");
        item3.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item3.setPicUrl("https://imgsa.baidu.com/baike/s%3D220/sign=a27ec7b4fbd3572c62e29bdeba126352/2934349b033b5bb56145b0a33fd3d539b700bcd9.jpg");
        item3.setUrl("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&ch=10&tn=90770921_hao_pg&wd=2017%E5%B0%84%E9%9B%95%E8%8B%B1%E9%9B%84%E7%99%BE%E7%A7%91&oq=2017%25E5%25B0%2584%25E9%259B%2595%25E8%258B%25B1%25E9%259B%2584&rsv_pq=fd94e92e00021171&rsv_t=a9d6csnnFSb6vQZOwQIkUhLa0tbfVRoYq11SGJstKyVmNcuA91AHmslzySkVTkHY5G6UOb3L&rqlang=cn&rsv_enter=0&inputT=1206&rsv_sug3=23&rsv_sug1=10&rsv_sug7=100&rsv_sug2=0&rsv_sug4=2273");

        Item item4 = new Item();
        item4.setTitle("《射雕英雄传》郭靖");
        item4.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item4.setPicUrl("https://imgsa.baidu.com/baike/crop%3D0%2C0%2C441%2C625%3Bh%3D195%3Bq%3D95/sign=817fd1005cfbb2fb20640252727a0c94/c2cec3fdfc0392450e1938528e94a4c27d1e253b.jpg");
        item4.setUrl("http://www.baidu.com");

        Item item5 = new Item();
        item5.setTitle("《射雕英雄传》黄蓉");
        item5.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item5.setPicUrl("https://imgsa.baidu.com/baike/crop%3D0%2C0%2C587%2C834%3Bh%3D195%3Bq%3D95/sign=d869bd502f9759ee5e1f3a8b8fcb6f26/f9dcd100baa1cd11a218ab7db012c8fcc2ce2dc5.jpg");
        item5.setUrl("http://www.baidu.com");

        Item item6 = new Item();
        item6.setTitle("《射雕英雄传》穆念慈");
        item6.setDescription("《射雕英雄传》是蒋家骏执导的古装武侠剧，由杨旭文、李一桐、陈星旭、孟子义等领衔主演");
        item6.setPicUrl("https://imgsa.baidu.com/baike/crop%3D0%2C0%2C620%2C880%3Bh%3D195%3Bq%3D95/sign=7d5e9bfba944ad343af0ddc7ed9220c4/b64543a98226cffcf26a86a4b1014a90f603ea60.jpg");
        item6.setUrl("http://www.baidu.com");

        List<Item> articles = new ArrayList<Item>();
        articles.add(item1);
        articles.add(item2);
        articles.add(item3);
        articles.add(item4);
        articles.add(item5);
        articles.add(item6);

        PicText picText = new PicText();
        picText.setFromUserName(map.get("ToUserName"));
        picText.setToUserName(map.get("FromUserName"));
        picText.setMsgType(GlobalVar.NEWS);
        picText.setCreateTime(new Date().getTime());
        picText.setArticleCount(6);
        picText.setArticles(articles);//将article加入到picText中（只能存在一条article）

        String picTextXmlString = ObjToXmlUtil.objToXml(picText, "xml");
        System.out.println(thisName + "——多图文消息回复：" + picTextXmlString);
        return picTextXmlString;
    }
}

/*图文消息格式如下：
<xml>
	<ToUserName><![CDATA[toUser]]></ToUserName>
	<FromUserName><![CDATA[fromUser]]></FromUserName>
	<CreateTime>12345678</CreateTime>
	<MsgType><![CDATA[news]]></MsgType>
	<ArticleCount>2</ArticleCount>
	<Articles>
		<item>
			<Title><![CDATA[title1]]></Title> 
			<Description><![CDATA[description1]]></Description>
			<PicUrl><![CDATA[picurl]]></PicUrl>
			<Url><![CDATA[url]]></Url>
		</item>
		<item>
			<Title><![CDATA[title]]></Title>
			<Description><![CDATA[description]]></Description>
			<PicUrl><![CDATA[picurl]]></PicUrl>
			<Url><![CDATA[url]]></Url>
		</item>
	</Articles>
</xml>
*/